﻿using B.Auth.APi.Application.Command.Role;
using B.Auth.APi.Application.Command.Users;
using B.Auth.Domain.Entity;
using B.Auth.Domain.Repository;
using B.Auth.Enum;
using MediatR;

namespace B.Auth.APi.Application.CommandHand
{
    public class DelRoleUserCommandHand : IRequestHandler<DelRoleUserCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<RoleUser> db;

        public DelRoleUserCommandHand(IBaseRepository<RoleUser> db)
        {
            this.db = db;
        }

        public Task<ApiResult<int>> Handle(DelRoleUserCommand request, CancellationToken cancellationToken)
        {
            var result=new ApiResult<int>();
            result.Message = "删除成功";
            var list = db.GetAll().FirstOrDefault(x => x.RoleId == request.RoleId && x.UserId == request.userId);
            if (list != null)
            { 
            
                db.Delect(list);
            }
            return  Task.FromResult(result);
            
        }
    }
}
